package mybatis.conf;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by fin on 2017/7/8.
 */
public class MybatisConf {

    private static SqlSessionFactory sqlSessionFactory;

    static{

        InputStream inputStream = null;
        try
        {
            inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    public static SqlSession getSession(){
        return sqlSessionFactory.openSession();
    }

}
